package tech.aistar.prj.controller;

import tech.aistar.prj.model.pojo.Video;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/video/updateView")
public class UpdateViewController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Video video = (Video) req.getAttribute("video");
        System.out.println(video);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html lang='en'>");
        out.println("<head>");
        out.println("<meta charset='UTF-8'>");
        out.println("<meta http-equiv='X-UA-Compatible' content='IE=edge'>");
        out.println("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.println("<title>bootstrap是一款响应式的UI[User-Interface]框架</title>");
        out.println("<!-- 引入bootstrap.css - 开发环境/bootstrap.min.css - 生产环境-->");
        out.println("<link rel='stylesheet' href='/servlet/plugins/bootstrap-3.4.1-dist/css/bootstrap.css'>");
        out.println("<link rel='stylesheet' href='/servlet/css/video/release.css'>");
        out.println("</head>");
        out.println("<body>");

        out.println("<div class='container'>");
        out.println("<div class='row'>");
        out.println("<form action='/servlet/video/updateGet?vId="+video.getId()+"' method='post' class='form-horizontal' role='form'>");
        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-sm-2 control-label'>视频标题");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<input type='text' class='form-control' id='title' name='title' value='"+video.getTitle()+"'>");
        out.println("</div>");
        out.println("</div>");
        //原来的图片
        out.println("<div class='form-group'>");
        out.println("<label for='lastname' class='col-sm-2 control-label'>原来的图片");out.println("</label>");
        out.println("<div class='col-md-3'>");
        out.println("<img  src='../imgs/"+video.getVideoUrl()+"'>");
        out.println("</div>");
        out.println("</div>");
        out.println("<input type='hidden' id='vdUrl' value='"+video.getVideoUrl()+"'>");
        //需要修改的
        out.println("<div class='form-group'>");
        out.println("<label for='lastname' class='col-sm-2 control-label'>修改视频封面为");out.println("</label>");
        out.println("<div class='col-md-7'>");
        out.println("<div class='row' id='feng'>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p9.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p9.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p8.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p8.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p7.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p7.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p6.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p6.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p5.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p5.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p4.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p4.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p3.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p3.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p2.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p2.jpg'>");
        out.println("</div>");
        out.println("<div class='col-md-3'>");
        out.println("<input type='checkbox' value='p1.jpg' name='uVideoUrl'>");
        out.println("<img src='../imgs/p1.jpg'>");
        out.println("</div>");

        out.println("</div>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-sm-2 control-label'>点赞数");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<input type='number' class='form-control' id='likes' name='likes' value='"+video.getLikes()+"'>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-sm-2 control-label'>评分");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<input type='number' step='0.1' class='form-control' id='score' name='score' value='"+video.getScore()+"'>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<label for='firstname' class='col-md-2 control-label'>是否修改");out.println("</label>");
        out.println("<div class='col-md-5'>");
        out.println("<label class='radio-inline'>");
        if (video.getStatus()==0){
            out.println("<input type='radio' name='status' id='status' value='2' >修改保存为草稿");
            out.println("</label>");
            out.println("<label class='radio-inline'>");
            out.println("<input type='radio' name='status' id='status' checked value='0'>修改并发布");
        }else {
            out.println("<input type='radio' name='status' id='status' value='2' checked>修改保存为草稿");
            out.println("</label>");
            out.println("<label class='radio-inline'>");
            out.println("<input type='radio' name='status' id='status'  value='0'>修改并发布");
        }

        out.println("</label>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class='form-group'>");
        out.println("<div class='col-sm-offset-2 col-sm-10'>");
        out.println("<button type='submit' class='btn btn-success'>修改提交");out.println("</button>");
        out.println("</div>");
        out.println("</div>");
        out.println("</form>");
        out.println("</div>");

        out.println("</div>");


        out.println("<script src='/servlet/plugins/jquery.min.js'>");out.println("</script>");
        out.println("<script src='/servlet/plugins/bootstrap-3.4.1-dist/js/bootstrap.js'>");out.println("</script>");
        out.println("<script src='/servlet/js/video/release.js'>");out.println("</script>");
        out.println("</body>");
        out.println("</html>");
    }
}
